package com.xdy.redis.demo;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;

/**
 * @Author: XDY.
 * @Email: 2280944114@qq.com
 * @CreateTime: 2023-05-07  15:40
 * @Description: Lettuce客户端测试
 * @Version: 1.0
 */
public class LettuceDemo {
    public static void main(String[] args) {
        //构建连接RUI
        RedisURI redisURI = RedisURI.builder().redis("192.168.64.131").withPort(6379).withAuthentication("default", "07032539").build();
        //获取连接对象
        RedisClient redisClient = RedisClient.create(redisURI);
        //获取连接对象
        StatefulRedisConnection<String, String> connect = redisClient.connect();
        //获取同步命令行对象
        RedisCommands<String, String> commands = connect.sync();
        //添加string
        commands.set("key1","value1");
        System.out.println(commands.get("key1"));
        //添加哈希
        commands.hset("hset1","name","许琳康");
        commands.hset("hset1","age","20");
        System.out.println(commands.hgetall("hset1"));
        //添加list
        commands.lpush("list1","11","22","33","44","55");
        System.out.println(commands.lrange("list1", 0, -1));
        //添加set
        commands.sadd("set1","1","1","2","2","4","4");
        System.out.println(commands.smembers("set1"));
        //添加sorted-set
        commands.zadd("zset1",90,"A");
        commands.zadd("zset1",80,"B");
        commands.zadd("zset1",70,"C");
        commands.zadd("zset1",60,"D");
        System.out.println(commands.zrange("zset1", 0, -1));
        //释放资源
        connect.close();
        redisClient.shutdown();
    }
}
